<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>CentOS 7.2安装Redis 5.0.3集群 | Joey</title><meta name="keywords" content="Linux,CentOS,Redis"><meta name="author" content="方陈勇"><meta name="copyright" content="方陈勇"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="CentOS 7.2安装Redis 5.0.3集群">
<meta property="og:type" content="article">
<meta property="og:title" content="CentOS 7.2安装Redis 5.0.3集群">
<meta property="og:url" content="http://fangchenyong.top/2019/07/23/Linux-install_Redis5.0.3_cluster/index.html">
<meta property="og:site_name" content="Joey">
<meta property="og:description" content="CentOS 7.2安装Redis 5.0.3集群">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/BEF238F4E59CF4D91A694FE9C5DBC030.JPG">
<meta property="article:published_time" content="2019-07-22T16:00:00.000Z">
<meta property="article:modified_time" content="2020-05-22T09:58:46.038Z">
<meta property="article:author" content="方陈勇">
<meta property="article:tag" content="Linux">
<meta property="article:tag" content="CentOS">
<meta property="article:tag" content="Redis">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/BEF238F4E59CF4D91A694FE9C5DBC030.JPG"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://fangchenyong.top/2019/07/23/Linux-install_Redis5.0.3_cluster/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2020-05-22 17:58:46'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    })(window)</script><meta name="generator" content="Hexo 5.4.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/3FD9B055-6361-49B7-B8CE-5BA9144BD27F.JPG" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">40</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">47</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">49</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> Archives</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> List</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> Music</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> Movie</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> Link</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> About</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/20190723151525.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">Joey</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> Archives</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> List</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> Music</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> Movie</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> Link</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> About</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">CentOS 7.2安装Redis 5.0.3集群</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2019-07-22T16:00:00.000Z" title="发表于 2019-07-23 00:00:00">2019-07-23</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2020-05-22T09:58:46.038Z" title="更新于 2020-05-22 17:58:46">2020-05-22</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Linux/">Linux</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Linux/CentOS/">CentOS</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Linux/CentOS/Redis/">Redis</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.6k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>8分钟</span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="CentOS-7-2安装Redis-5-0-3集群"><a href="#CentOS-7-2安装Redis-5-0-3集群" class="headerlink" title="CentOS 7.2安装Redis 5.0.3集群"></a>CentOS 7.2安装Redis 5.0.3集群</h2><h4 id="1-安装redis-5-0（参考install-Redis5-0-3-md）"><a href="#1-安装redis-5-0（参考install-Redis5-0-3-md）" class="headerlink" title="1. 安装redis 5.0（参考install_Redis5.0.3.md）"></a>1. 安装redis 5.0（参考install_Redis5.0.3.md）</h4><h4 id="2-创建redis-cluster目录，方便管理我们创建的redis实例，复制之前安装好的redis为redis01"><a href="#2-创建redis-cluster目录，方便管理我们创建的redis实例，复制之前安装好的redis为redis01" class="headerlink" title="2. 创建redis-cluster目录，方便管理我们创建的redis实例，复制之前安装好的redis为redis01"></a>2. 创建redis-cluster目录，方便管理我们创建的redis实例，复制之前安装好的redis为redis01</h4><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">[root@VM_0_5_centos redis]# mkdir redis-cluster</span><br><span class="line">[root@VM_0_5_centos redis]# ls</span><br><span class="line">log  redis-5.0.3  redis-5.0.3.tar.gz  redis-cluster</span><br><span class="line">[root@VM_0_5_centos redis]# cp -r redis-5.0.3 ./redis-cluster/redis01</span><br><span class="line">[root@VM_0_5_centos redis]# ls redis-cluster/</span><br><span class="line">redis01</span><br></pre></td></tr></table></figure>

<h4 id="3-修改redis01的配置文件"><a href="#3-修改redis01的配置文件" class="headerlink" title="3. 修改redis01的配置文件"></a>3. 修改redis01的配置文件</h4><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">[root@VM_0_5_centos redis]# cd redis-cluster/redis01/</span><br><span class="line">[root@VM_0_5_centos redis01]# ls</span><br><span class="line">00-RELEASENOTES  COPYING  Makefile   redis.conf       runtest-sentinel  tests</span><br><span class="line">BUGS             deps     MANIFESTO  runtest          sentinel.conf     utils</span><br><span class="line">CONTRIBUTING     INSTALL  README.md  runtest-cluster  src</span><br><span class="line">[root@VM_0_5_centos redis01]# vim redis.conf </span><br></pre></td></tr></table></figure>

<h4 id="4-把-bind-127-0-0-1-给注释掉或者改为0-0-0-0，这里的bind指的是只有指定的网段才能远程访问这个redis"><a href="#4-把-bind-127-0-0-1-给注释掉或者改为0-0-0-0，这里的bind指的是只有指定的网段才能远程访问这个redis" class="headerlink" title="4. 把 bind 127.0.0.1 给注释掉或者改为0.0.0.0，这里的bind指的是只有指定的网段才能远程访问这个redis"></a>4. 把 bind 127.0.0.1 给注释掉或者改为0.0.0.0，这里的bind指的是只有指定的网段才能远程访问这个redis</h4><p><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/%E9%9B%86%E7%BE%A41.png" alt="集群1"></p>
<h4 id="5-开启远程访问-protected-mode-no-和-修改端口-port-7001"><a href="#5-开启远程访问-protected-mode-no-和-修改端口-port-7001" class="headerlink" title="5. 开启远程访问 protected-mode no 和 修改端口 port 7001"></a>5. 开启远程访问 protected-mode no 和 修改端口 port 7001</h4><p><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/%E9%9B%86%E7%BE%A42.png" alt="集群2"></p>
<h4 id="6-设置后台运行-daemonize-yes"><a href="#6-设置后台运行-daemonize-yes" class="headerlink" title="6. 设置后台运行 daemonize yes"></a>6. 设置后台运行 daemonize yes</h4><p><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/%E9%9B%86%E7%BE%A43.png" alt="集群3"></p>
<h4 id="7-设置pidfile存放在-run目录下的文件名-pidfile-var-run-redis-7001-pid"><a href="#7-设置pidfile存放在-run目录下的文件名-pidfile-var-run-redis-7001-pid" class="headerlink" title="7. 设置pidfile存放在 run目录下的文件名  pidfile  /var/run/redis_7001.pid"></a>7. 设置pidfile存放在 run目录下的文件名  pidfile  /var/run/redis_7001.pid</h4><p><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/%E9%9B%86%E7%BE%A44.png" alt="集群4"></p>
<h4 id="8-设置redis集群密码-masterauth-123456-和-requirepass-123456-注意：所有节点的密码都必须一致，masterauth也要加"><a href="#8-设置redis集群密码-masterauth-123456-和-requirepass-123456-注意：所有节点的密码都必须一致，masterauth也要加" class="headerlink" title="8. 设置redis集群密码 masterauth 123456 和 requirepass 123456       注意：所有节点的密码都必须一致，masterauth也要加"></a>8. 设置redis集群密码 masterauth 123456 和 requirepass 123456       注意：所有节点的密码都必须一致，masterauth也要加</h4><p><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/%E9%9B%86%E7%BE%A45.1.png" alt="集群5.1"></p>
<p><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/%E9%9B%86%E7%BE%A45.2.png" alt="集群5.2"></p>
<h4 id="9-设置开启AOF模式-appendonly-yes"><a href="#9-设置开启AOF模式-appendonly-yes" class="headerlink" title="9. 设置开启AOF模式  appendonly yes"></a>9. 设置开启AOF模式  appendonly yes</h4><p><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/%E9%9B%86%E7%BE%A46.png" alt="集群6"></p>
<h4 id="10-设置启用集群模式-cluster-enabled-yes，开启配置文件cluster-config-file-nodes-conf-，超时时间-cluster-node-timeout-5000"><a href="#10-设置启用集群模式-cluster-enabled-yes，开启配置文件cluster-config-file-nodes-conf-，超时时间-cluster-node-timeout-5000" class="headerlink" title="10. 设置启用集群模式 cluster-enabled yes，开启配置文件cluster-config-file nodes.conf ，超时时间 cluster-node-timeout 5000"></a>10. 设置启用集群模式 cluster-enabled yes，开启配置文件cluster-config-file nodes.conf ，超时时间 cluster-node-timeout 5000</h4><p><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/%E9%9B%86%E7%BE%A47.png" alt="集群7"></p>
<h4 id="11-配置好后，拷贝-redis01再创建五个redis实例"><a href="#11-配置好后，拷贝-redis01再创建五个redis实例" class="headerlink" title="11. 配置好后，拷贝 redis01再创建五个redis实例"></a>11. 配置好后，拷贝 redis01再创建五个redis实例</h4><p><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/%E9%9B%86%E7%BE%A48.png" alt="集群8"></p>
<h4 id="12-修改redis02-06的配置文件，修改端口号，修改pidfile存放文件名"><a href="#12-修改redis02-06的配置文件，修改端口号，修改pidfile存放文件名" class="headerlink" title="12. 修改redis02~06的配置文件，修改端口号，修改pidfile存放文件名"></a>12. 修改redis02~06的配置文件，修改端口号，修改pidfile存放文件名</h4><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">[root@VM_0_5_centos redis-cluster]# vim redis02/redis.conf </span><br><span class="line">[root@VM_0_5_centos redis-cluster]# vim redis03/redis.conf </span><br><span class="line">[root@VM_0_5_centos redis-cluster]# vim redis04/redis.conf </span><br><span class="line">[root@VM_0_5_centos redis-cluster]# vim redis05/redis.conf </span><br><span class="line">[root@VM_0_5_centos redis-cluster]# vim redis06/redis.conf </span><br></pre></td></tr></table></figure>

<h4 id="13-在redis-cluster目录下，编写redis-start-all-sh启动脚本，启动redis实例"><a href="#13-在redis-cluster目录下，编写redis-start-all-sh启动脚本，启动redis实例" class="headerlink" title="13. 在redis-cluster目录下，编写redis_start_all.sh启动脚本，启动redis实例"></a>13. 在redis-cluster目录下，编写redis_start_all.sh启动脚本，启动redis实例</h4><p><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/%E9%9B%86%E7%BE%A410.png" alt="集群10"></p>
<h4 id="14-刚创建好的启动脚本没有权限，会提示Permission-denied，所以需要给脚本添加可执行权限"><a href="#14-刚创建好的启动脚本没有权限，会提示Permission-denied，所以需要给脚本添加可执行权限" class="headerlink" title="14. 刚创建好的启动脚本没有权限，会提示Permission denied，所以需要给脚本添加可执行权限"></a>14. 刚创建好的启动脚本没有权限，会提示Permission denied，所以需要给脚本添加可执行权限</h4><p><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/%E9%9B%86%E7%BE%A411.png" alt="集群11"></p>
<blockquote>
<p><strong>权限部分说明</strong></p>
<blockquote>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">-rw-r--r-- 1 root root  490 Jan 13 22:32 redis_cluster_start_all.sh</span><br></pre></td></tr></table></figure>

<p><strong>含义</strong></p>
<p>u 代表所有者（user）<br>g 代表所有者所在的组群（group）<br>o 代表其他用户（other）<br>a 代表全部的人（u、g、o）</p>
<p>r 表示文件可读（read）<br>w 表示文件可写（write）<br>x 表示文件可执行（是程序）<br>– 表示相应的权限为空</p>
<p>+ 表示添加权限<br>– 表示删除权限<br>= 表示使之成为唯一的权限</p>
<p><strong>数字表示</strong></p>
<p>0代表—<br>1代表–x<br>2代表-w-<br>3代表-wx<br>4代表r–<br>5代表r-x<br>6代表rw-<br>7代表rwx</p>
<p>-rw——-    (600) 只有所有者才有读和写的权限</p>
<p>-rw-r–r–    (644) 只有所有者才有读和写的权限，组群和其他用户只有读的权限</p>
<p>-rwx——    (700) 只有所有者才有读，写，执行的权限</p>
<p>-rwxr-xr-x    (755) 只有所有者才有读，写，执行的权限，组群和其他用户只有读和执行的权限</p>
<p>-rwx–x–x    (711) 只有所有者才有读，写，执行的权限，组群和其用户只有执行的权限</p>
<p>-rw-rw-rw- (666) 每个人都有读写的权限</p>
<p>-rwxrwxrwx (777) 每个人都有读写和执行的权限</p>
</blockquote>
</blockquote>
<h4 id="15-启动redis集群"><a href="#15-启动redis集群" class="headerlink" title="15. 启动redis集群"></a>15. 启动redis集群</h4><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">[root@VM_0_5_centos redis-cluster]# ./redis_cluster_start_all.sh</span><br></pre></td></tr></table></figure>

<p><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/%E9%9B%86%E7%BE%A412.png" alt="集群12"></p>
<h4 id="16-复进入到redis01-bin-目录下，拷贝一份-redis-cli-到-redis-cluster-目录下"><a href="#16-复进入到redis01-bin-目录下，拷贝一份-redis-cli-到-redis-cluster-目录下" class="headerlink" title="16. 复进入到redis01/bin/ 目录下，拷贝一份 redis-cli 到  redis-cluster/ 目录下"></a>16. 复进入到redis01/bin/ 目录下，拷贝一份 redis-cli 到  redis-cluster/ 目录下</h4><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">[root@VM_0_5_centos src]# cp redis-cli /usr/local/redis/redis-cluster/</span><br><span class="line">[root@VM_0_5_centos src]# ls ../../</span><br><span class="line">redis01  redis02  redis03  redis04  redis05  redis06  redis-cli  redis_cluster_start_all.sh</span><br></pre></td></tr></table></figure>

<h4 id="17-创建redis集群"><a href="#17-创建redis集群" class="headerlink" title="17. 创建redis集群"></a>17. 创建redis集群</h4><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">[root@VM_0_5_centos redis-cluster]# ./redis-cli --cluster create 118.25.24.23:7001 118.25.24.23:7002 118.25.24.23:7003 118.25.24.23:7004 118.25.24.23:7005 118.25.24.23:7006 --cluster-replicas 1 -a 123456</span><br><span class="line">Warning: Using a password with &#x27;-a&#x27; or &#x27;-u&#x27; option on the command line interface may not be safe.</span><br><span class="line"><span class="meta">&gt;</span><span class="bash">&gt;&gt; Performing <span class="built_in">hash</span> slots allocation on 6 nodes...</span></span><br><span class="line">Master[0] -&gt; Slots 0 - 5460</span><br><span class="line">Master[1] -&gt; Slots 5461 - 10922</span><br><span class="line">Master[2] -&gt; Slots 10923 - 16383</span><br><span class="line">Adding replica 118.25.24.23:7004 to 118.25.24.23:7001</span><br><span class="line">Adding replica 118.25.24.23:7005 to 118.25.24.23:7002</span><br><span class="line">Adding replica 118.25.24.23:7006 to 118.25.24.23:7003</span><br><span class="line"><span class="meta">&gt;</span><span class="bash">&gt;&gt; Trying to optimize slaves allocation <span class="keyword">for</span> anti-affinity</span></span><br><span class="line">[WARNING] Some slaves are in the same host as their master</span><br><span class="line">M: b50c435cf63df50862a94dadadd9ca5e051449fd 118.25.24.23:7001</span><br><span class="line">   slots:[0-5460] (5461 slots) master</span><br><span class="line">M: acf23e9fdab3c902d3cdae65b3120361aabb916f 118.25.24.23:7002</span><br><span class="line">   slots:[5461-10922] (5462 slots) master</span><br><span class="line">M: 9608312874a165adcea031713c5256c4c3d7eb63 118.25.24.23:7003</span><br><span class="line">   slots:[10923-16383] (5461 slots) master</span><br><span class="line">S: 30a12a011575d62c8865c0e9249e7e768c1a9bae 118.25.24.23:7004</span><br><span class="line">   replicates acf23e9fdab3c902d3cdae65b3120361aabb916f</span><br><span class="line">S: 1733a42b8b6471f81d9dab5f8213ea62b1492fe8 118.25.24.23:7005</span><br><span class="line">   replicates 9608312874a165adcea031713c5256c4c3d7eb63</span><br><span class="line">S: dfac6c68ed0204eda79ceff6b4fd688b1e68df7e 118.25.24.23:7006</span><br><span class="line">   replicates b50c435cf63df50862a94dadadd9ca5e051449fd</span><br><span class="line">Can I set the above configuration? (type &#x27;yes&#x27; to accept): yes</span><br><span class="line"><span class="meta">&gt;</span><span class="bash">&gt;&gt; Nodes configuration updated</span></span><br><span class="line"><span class="meta">&gt;</span><span class="bash">&gt;&gt; Assign a different config epoch to each node</span></span><br><span class="line"><span class="meta">&gt;</span><span class="bash">&gt;&gt; Sending CLUSTER MEET messages to join the cluster</span></span><br><span class="line">Waiting for the cluster to join</span><br><span class="line">...</span><br><span class="line"><span class="meta">&gt;</span><span class="bash">&gt;&gt; Performing Cluster Check (using node 118.25.24.23:7001)</span></span><br><span class="line">M: b50c435cf63df50862a94dadadd9ca5e051449fd 118.25.24.23:7001</span><br><span class="line">   slots:[0-5460] (5461 slots) master</span><br><span class="line">   1 additional replica(s)</span><br><span class="line">S: dfac6c68ed0204eda79ceff6b4fd688b1e68df7e 118.25.24.23:7006</span><br><span class="line">   slots: (0 slots) slave</span><br><span class="line">   replicates b50c435cf63df50862a94dadadd9ca5e051449fd</span><br><span class="line">S: 1733a42b8b6471f81d9dab5f8213ea62b1492fe8 118.25.24.23:7005</span><br><span class="line">   slots: (0 slots) slave</span><br><span class="line">   replicates 9608312874a165adcea031713c5256c4c3d7eb63</span><br><span class="line">M: acf23e9fdab3c902d3cdae65b3120361aabb916f 118.25.24.23:7002</span><br><span class="line">   slots:[5461-10922] (5462 slots) master</span><br><span class="line">   1 additional replica(s)</span><br><span class="line">S: 30a12a011575d62c8865c0e9249e7e768c1a9bae 118.25.24.23:7004</span><br><span class="line">   slots: (0 slots) slave</span><br><span class="line">   replicates acf23e9fdab3c902d3cdae65b3120361aabb916f</span><br><span class="line">M: 9608312874a165adcea031713c5256c4c3d7eb63 118.25.24.23:7003</span><br><span class="line">   slots:[10923-16383] (5461 slots) master</span><br><span class="line">   1 additional replica(s)</span><br><span class="line">[OK] All nodes agree about slots configuration.</span><br><span class="line"><span class="meta">&gt;</span><span class="bash">&gt;&gt; Check <span class="keyword">for</span> open slots...</span></span><br><span class="line"><span class="meta">&gt;</span><span class="bash">&gt;&gt; Check slots coverage...</span></span><br><span class="line">[OK] All 16384 slots covered.</span><br></pre></td></tr></table></figure>

<h4 id="18-在redis-cluster目录下，编写redis-cluster-stop-all-sh关闭脚本"><a href="#18-在redis-cluster目录下，编写redis-cluster-stop-all-sh关闭脚本" class="headerlink" title="18. 在redis-cluster目录下，编写redis_cluster_stop_all.sh关闭脚本"></a>18. 在redis-cluster目录下，编写redis_cluster_stop_all.sh关闭脚本</h4><p><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/%E9%9B%86%E7%BE%A415.png" alt="集群15"></p>
<h4 id="19-给redis-cluster-stop-all-sh脚本添加可执行权限-参考11点给启动脚本添加权限"><a href="#19-给redis-cluster-stop-all-sh脚本添加可执行权限-参考11点给启动脚本添加权限" class="headerlink" title="19. 给redis_cluster_stop_all.sh脚本添加可执行权限(参考11点给启动脚本添加权限)"></a>19. 给redis_cluster_stop_all.sh脚本添加可执行权限(参考11点给启动脚本添加权限)</h4><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">[root@VM_0_5_centos redis-cluster]# ll | grep redis_cluster_stop_all.sh</span><br><span class="line">-rw-r--r-- 1 root root     552 Jan 14 10:42 redis_cluster_stop_all.sh</span><br><span class="line">[root@VM_0_5_centos redis-cluster]# chmod +x redis_cluster_stop_all.sh </span><br><span class="line">[root@VM_0_5_centos redis-cluster]# ll | grep redis_cluster_stop_all.sh</span><br><span class="line">-rwxr-xr-x 1 root root     552 Jan 14 10:42 redis_cluster_stop_all.sh</span><br></pre></td></tr></table></figure>

<p><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/%E9%9B%86%E7%BE%A416.png" alt="集群16"></p>
<h4 id="20-执行停止脚本"><a href="#20-执行停止脚本" class="headerlink" title="20. 执行停止脚本"></a>20. 执行停止脚本</h4><p><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/%E9%9B%86%E7%BE%A417.png" alt="集群17"></p>
<h4 id="21-java使用jedis连接集群"><a href="#21-java使用jedis连接集群" class="headerlink" title="21. java使用jedis连接集群"></a>21. java使用jedis连接集群</h4><blockquote>
<ol>
<li><strong>pom.xml中引入相关jar包</strong></li>
</ol>
<figure class="highlight xml"><table><tr><td class="code"><pre><span class="line"><span class="comment">&lt;!--整合redis--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-data-redis<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.1.1.RELEASE<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">&lt;!-- https://mvnrepository.com/artifact/redis.clients/jedis --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>redis.clients<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>jedis<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>3.0.1<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<ol start="2">
<li><strong>配置文件中添加集群节点信息</strong></li>
</ol>
<figure class="highlight yaml"><table><tr><td class="code"><pre><span class="line"><span class="attr">spring:</span> </span><br><span class="line">  <span class="attr">redis:</span></span><br><span class="line">    <span class="attr">cluster:</span></span><br><span class="line">      <span class="attr">nodes:</span> <span class="number">118.25</span><span class="number">.24</span><span class="number">.23</span><span class="string">:7001,118.25.24.23:7002,118.25.24.23:7003,118.25.24.23:7004,118.25.24.23:7005,118.25.24.23:7006</span></span><br></pre></td></tr></table></figure>

<ol start="3">
<li><strong>编写redis配置类</strong></li>
</ol>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">package</span> com.joey.config;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.annotation.Value;</span><br><span class="line"><span class="keyword">import</span> org.springframework.context.annotation.Bean;</span><br><span class="line"><span class="keyword">import</span> org.springframework.context.annotation.Configuration;</span><br><span class="line"><span class="keyword">import</span> redis.clients.jedis.HostAndPort;</span><br><span class="line"><span class="keyword">import</span> redis.clients.jedis.JedisCluster;</span><br><span class="line"><span class="keyword">import</span> redis.clients.jedis.JedisPoolConfig;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.HashSet;</span><br><span class="line"><span class="keyword">import</span> java.util.Set;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 〈redis集群配置〉</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> Joey</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@create</span> 2019-01-14</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@since</span> 1.0.0</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">RedisConfig</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Value(&quot;$&#123;spring.redis.cluster.nodes&#125;&quot;)</span></span><br><span class="line">    <span class="keyword">private</span> String redisNodes;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> JedisCluster <span class="title">getJedisCluster</span><span class="params">()</span></span>&#123;</span><br><span class="line">        Set&lt;HostAndPort&gt; nodes = <span class="keyword">new</span> HashSet&lt;&gt;();</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            String[] redisnodes = redisNodes.split(<span class="string">&quot;,&quot;</span>);</span><br><span class="line">            <span class="keyword">for</span> (String node:redisnodes)&#123;</span><br><span class="line">                String[] arr = node.split(<span class="string">&quot;:&quot;</span>);</span><br><span class="line">                HostAndPort hostAndPort = <span class="keyword">new</span> HostAndPort(arr[<span class="number">0</span>], Integer.parseInt(arr[<span class="number">1</span>]));</span><br><span class="line">                nodes.add(hostAndPort);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">catch</span> (Exception e)&#123;</span><br><span class="line">            System.out.println(<span class="string">&quot;集群节点配置有误&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        JedisPoolConfig jedisPoolConfig = <span class="keyword">new</span> JedisPoolConfig();</span><br><span class="line">        <span class="comment">//配置password否则会报权限错误</span></span><br><span class="line">        JedisCluster cluster = <span class="keyword">new</span> JedisCluster(nodes,<span class="number">0</span>,<span class="number">0</span>,<span class="number">500</span>,<span class="string">&quot;123456&quot;</span>,jedisPoolConfig);</span><br><span class="line">        <span class="keyword">return</span> cluster;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol start="4">
<li><p><strong>编写Service接口类，实现类以及Controller类</strong></p>
<p>(1). 接口类</p>
</li>
</ol>
<p><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/%E9%9B%86%E7%BE%A4%E6%8E%A5%E5%8F%A3%E7%B1%BB.png" alt="集群接口类"></p>
<p>​    (2). 实现类</p>
<p><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/%E9%9B%86%E7%BE%A4%E5%AE%9E%E7%8E%B0%E7%B1%BB.png" alt="集群实现类"></p>
<p>​    (3). Controller类</p>
<p><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/%E9%9B%86%E7%BE%A4%E6%8E%A7%E5%88%B6%E7%B1%BB.png" alt="集群控制类"></p>
<ol start="5">
<li><strong>浏览器访问</strong></li>
</ol>
<p><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/%E9%9B%86%E7%BE%A4%E6%88%90%E5%8A%9F.png" alt="集群成功"></p>
</blockquote>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">方陈勇</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://fangchenyong.top/2019/07/23/Linux-install_Redis5.0.3_cluster/">http://fangchenyong.top/2019/07/23/Linux-install_Redis5.0.3_cluster/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://fangchenyong.top" target="_blank">Joey</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Linux/">Linux</a><a class="post-meta__tags" href="/tags/CentOS/">CentOS</a><a class="post-meta__tags" href="/tags/Redis/">Redis</a></div><div class="post_share"><div class="social-share" data-image="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/BEF238F4E59CF4D91A694FE9C5DBC030.JPG" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2019/07/23/Linux-install_Redis5.0.3/"><img class="prev-cover" src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/BEF238F4E59CF4D91A694FE9C5DBC030.JPG" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Centos 7.2 安装目前最新版Redis5.0.3</div></div></a></div><div class="next-post pull-right"><a href="/2019/07/23/Linux-install_Tomcat8/"><img class="next-cover" src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/BEF238F4E59CF4D91A694FE9C5DBC030.JPG" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">CentOS7.2 安装tomcat8.5</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2019/07/23/Linux-install_Redis5.0.3/" title="Centos 7.2 安装目前最新版Redis5.0.3"><img class="cover" src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/BEF238F4E59CF4D91A694FE9C5DBC030.JPG" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-07-23</div><div class="title">Centos 7.2 安装目前最新版Redis5.0.3</div></div></a></div><div><a href="/2019/08/14/Linux-install_FastDFS+Nginx/" title="CentOS7 安装FastDFS+nginx"><img class="cover" src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/BEF238F4E59CF4D91A694FE9C5DBC030.JPG" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-08-14</div><div class="title">CentOS7 安装FastDFS+nginx</div></div></a></div><div><a href="/2019/07/23/Linux-install_ActiveMQ/" title="CentOS 7.2安装ActiveMQ 5.14.5"><img class="cover" src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/BEF238F4E59CF4D91A694FE9C5DBC030.JPG" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-07-23</div><div class="title">CentOS 7.2安装ActiveMQ 5.14.5</div></div></a></div><div><a href="/2019/07/23/Linux-install_JDK1.8/" title="Centos7.2下安装JDK三种方法"><img class="cover" src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/BEF238F4E59CF4D91A694FE9C5DBC030.JPG" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-07-23</div><div class="title">Centos7.2下安装JDK三种方法</div></div></a></div><div><a href="/2019/07/23/Linux-install_MongoDB4.0.5/" title="CentOS 7.2安装MongoDB 4.0.5"><img class="cover" src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/BEF238F4E59CF4D91A694FE9C5DBC030.JPG" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-07-23</div><div class="title">CentOS 7.2安装MongoDB 4.0.5</div></div></a></div><div><a href="/2019/07/23/Linux-install_MySql5.7/" title="CentOS 7.2 安装MySql 5.7"><img class="cover" src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/BEF238F4E59CF4D91A694FE9C5DBC030.JPG" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-07-23</div><div class="title">CentOS 7.2 安装MySql 5.7</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/3FD9B055-6361-49B7-B8CE-5BA9144BD27F.JPG" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">方陈勇</div><div class="author-info__description">一路向前</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">40</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">47</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">49</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/fangchenyong"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/fangchenyong" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:1013659102@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">个人笔记，如有疑问请联系 QQ:1013659102。</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#CentOS-7-2%E5%AE%89%E8%A3%85Redis-5-0-3%E9%9B%86%E7%BE%A4"><span class="toc-number">1.</span> <span class="toc-text">CentOS 7.2安装Redis 5.0.3集群</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E5%AE%89%E8%A3%85redis-5-0%EF%BC%88%E5%8F%82%E8%80%83install-Redis5-0-3-md%EF%BC%89"><span class="toc-number">1.0.1.</span> <span class="toc-text">1. 安装redis 5.0（参考install_Redis5.0.3.md）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E5%88%9B%E5%BB%BAredis-cluster%E7%9B%AE%E5%BD%95%EF%BC%8C%E6%96%B9%E4%BE%BF%E7%AE%A1%E7%90%86%E6%88%91%E4%BB%AC%E5%88%9B%E5%BB%BA%E7%9A%84redis%E5%AE%9E%E4%BE%8B%EF%BC%8C%E5%A4%8D%E5%88%B6%E4%B9%8B%E5%89%8D%E5%AE%89%E8%A3%85%E5%A5%BD%E7%9A%84redis%E4%B8%BAredis01"><span class="toc-number">1.0.2.</span> <span class="toc-text">2. 创建redis-cluster目录，方便管理我们创建的redis实例，复制之前安装好的redis为redis01</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-%E4%BF%AE%E6%94%B9redis01%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="toc-number">1.0.3.</span> <span class="toc-text">3. 修改redis01的配置文件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-%E6%8A%8A-bind-127-0-0-1-%E7%BB%99%E6%B3%A8%E9%87%8A%E6%8E%89%E6%88%96%E8%80%85%E6%94%B9%E4%B8%BA0-0-0-0%EF%BC%8C%E8%BF%99%E9%87%8C%E7%9A%84bind%E6%8C%87%E7%9A%84%E6%98%AF%E5%8F%AA%E6%9C%89%E6%8C%87%E5%AE%9A%E7%9A%84%E7%BD%91%E6%AE%B5%E6%89%8D%E8%83%BD%E8%BF%9C%E7%A8%8B%E8%AE%BF%E9%97%AE%E8%BF%99%E4%B8%AAredis"><span class="toc-number">1.0.4.</span> <span class="toc-text">4. 把 bind 127.0.0.1 给注释掉或者改为0.0.0.0，这里的bind指的是只有指定的网段才能远程访问这个redis</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-%E5%BC%80%E5%90%AF%E8%BF%9C%E7%A8%8B%E8%AE%BF%E9%97%AE-protected-mode-no-%E5%92%8C-%E4%BF%AE%E6%94%B9%E7%AB%AF%E5%8F%A3-port-7001"><span class="toc-number">1.0.5.</span> <span class="toc-text">5. 开启远程访问 protected-mode no 和 修改端口 port 7001</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#6-%E8%AE%BE%E7%BD%AE%E5%90%8E%E5%8F%B0%E8%BF%90%E8%A1%8C-daemonize-yes"><span class="toc-number">1.0.6.</span> <span class="toc-text">6. 设置后台运行 daemonize yes</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#7-%E8%AE%BE%E7%BD%AEpidfile%E5%AD%98%E6%94%BE%E5%9C%A8-run%E7%9B%AE%E5%BD%95%E4%B8%8B%E7%9A%84%E6%96%87%E4%BB%B6%E5%90%8D-pidfile-var-run-redis-7001-pid"><span class="toc-number">1.0.7.</span> <span class="toc-text">7. 设置pidfile存放在 run目录下的文件名  pidfile  &#x2F;var&#x2F;run&#x2F;redis_7001.pid</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#8-%E8%AE%BE%E7%BD%AEredis%E9%9B%86%E7%BE%A4%E5%AF%86%E7%A0%81-masterauth-123456-%E5%92%8C-requirepass-123456-%E6%B3%A8%E6%84%8F%EF%BC%9A%E6%89%80%E6%9C%89%E8%8A%82%E7%82%B9%E7%9A%84%E5%AF%86%E7%A0%81%E9%83%BD%E5%BF%85%E9%A1%BB%E4%B8%80%E8%87%B4%EF%BC%8Cmasterauth%E4%B9%9F%E8%A6%81%E5%8A%A0"><span class="toc-number">1.0.8.</span> <span class="toc-text">8. 设置redis集群密码 masterauth 123456 和 requirepass 123456       注意：所有节点的密码都必须一致，masterauth也要加</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#9-%E8%AE%BE%E7%BD%AE%E5%BC%80%E5%90%AFAOF%E6%A8%A1%E5%BC%8F-appendonly-yes"><span class="toc-number">1.0.9.</span> <span class="toc-text">9. 设置开启AOF模式  appendonly yes</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#10-%E8%AE%BE%E7%BD%AE%E5%90%AF%E7%94%A8%E9%9B%86%E7%BE%A4%E6%A8%A1%E5%BC%8F-cluster-enabled-yes%EF%BC%8C%E5%BC%80%E5%90%AF%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6cluster-config-file-nodes-conf-%EF%BC%8C%E8%B6%85%E6%97%B6%E6%97%B6%E9%97%B4-cluster-node-timeout-5000"><span class="toc-number">1.0.10.</span> <span class="toc-text">10. 设置启用集群模式 cluster-enabled yes，开启配置文件cluster-config-file nodes.conf ，超时时间 cluster-node-timeout 5000</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#11-%E9%85%8D%E7%BD%AE%E5%A5%BD%E5%90%8E%EF%BC%8C%E6%8B%B7%E8%B4%9D-redis01%E5%86%8D%E5%88%9B%E5%BB%BA%E4%BA%94%E4%B8%AAredis%E5%AE%9E%E4%BE%8B"><span class="toc-number">1.0.11.</span> <span class="toc-text">11. 配置好后，拷贝 redis01再创建五个redis实例</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#12-%E4%BF%AE%E6%94%B9redis02-06%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%EF%BC%8C%E4%BF%AE%E6%94%B9%E7%AB%AF%E5%8F%A3%E5%8F%B7%EF%BC%8C%E4%BF%AE%E6%94%B9pidfile%E5%AD%98%E6%94%BE%E6%96%87%E4%BB%B6%E5%90%8D"><span class="toc-number">1.0.12.</span> <span class="toc-text">12. 修改redis02~06的配置文件，修改端口号，修改pidfile存放文件名</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#13-%E5%9C%A8redis-cluster%E7%9B%AE%E5%BD%95%E4%B8%8B%EF%BC%8C%E7%BC%96%E5%86%99redis-start-all-sh%E5%90%AF%E5%8A%A8%E8%84%9A%E6%9C%AC%EF%BC%8C%E5%90%AF%E5%8A%A8redis%E5%AE%9E%E4%BE%8B"><span class="toc-number">1.0.13.</span> <span class="toc-text">13. 在redis-cluster目录下，编写redis_start_all.sh启动脚本，启动redis实例</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#14-%E5%88%9A%E5%88%9B%E5%BB%BA%E5%A5%BD%E7%9A%84%E5%90%AF%E5%8A%A8%E8%84%9A%E6%9C%AC%E6%B2%A1%E6%9C%89%E6%9D%83%E9%99%90%EF%BC%8C%E4%BC%9A%E6%8F%90%E7%A4%BAPermission-denied%EF%BC%8C%E6%89%80%E4%BB%A5%E9%9C%80%E8%A6%81%E7%BB%99%E8%84%9A%E6%9C%AC%E6%B7%BB%E5%8A%A0%E5%8F%AF%E6%89%A7%E8%A1%8C%E6%9D%83%E9%99%90"><span class="toc-number">1.0.14.</span> <span class="toc-text">14. 刚创建好的启动脚本没有权限，会提示Permission denied，所以需要给脚本添加可执行权限</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#15-%E5%90%AF%E5%8A%A8redis%E9%9B%86%E7%BE%A4"><span class="toc-number">1.0.15.</span> <span class="toc-text">15. 启动redis集群</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#16-%E5%A4%8D%E8%BF%9B%E5%85%A5%E5%88%B0redis01-bin-%E7%9B%AE%E5%BD%95%E4%B8%8B%EF%BC%8C%E6%8B%B7%E8%B4%9D%E4%B8%80%E4%BB%BD-redis-cli-%E5%88%B0-redis-cluster-%E7%9B%AE%E5%BD%95%E4%B8%8B"><span class="toc-number">1.0.16.</span> <span class="toc-text">16. 复进入到redis01&#x2F;bin&#x2F; 目录下，拷贝一份 redis-cli 到  redis-cluster&#x2F; 目录下</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#17-%E5%88%9B%E5%BB%BAredis%E9%9B%86%E7%BE%A4"><span class="toc-number">1.0.17.</span> <span class="toc-text">17. 创建redis集群</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#18-%E5%9C%A8redis-cluster%E7%9B%AE%E5%BD%95%E4%B8%8B%EF%BC%8C%E7%BC%96%E5%86%99redis-cluster-stop-all-sh%E5%85%B3%E9%97%AD%E8%84%9A%E6%9C%AC"><span class="toc-number">1.0.18.</span> <span class="toc-text">18. 在redis-cluster目录下，编写redis_cluster_stop_all.sh关闭脚本</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#19-%E7%BB%99redis-cluster-stop-all-sh%E8%84%9A%E6%9C%AC%E6%B7%BB%E5%8A%A0%E5%8F%AF%E6%89%A7%E8%A1%8C%E6%9D%83%E9%99%90-%E5%8F%82%E8%80%8311%E7%82%B9%E7%BB%99%E5%90%AF%E5%8A%A8%E8%84%9A%E6%9C%AC%E6%B7%BB%E5%8A%A0%E6%9D%83%E9%99%90"><span class="toc-number">1.0.19.</span> <span class="toc-text">19. 给redis_cluster_stop_all.sh脚本添加可执行权限(参考11点给启动脚本添加权限)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#20-%E6%89%A7%E8%A1%8C%E5%81%9C%E6%AD%A2%E8%84%9A%E6%9C%AC"><span class="toc-number">1.0.20.</span> <span class="toc-text">20. 执行停止脚本</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#21-java%E4%BD%BF%E7%94%A8jedis%E8%BF%9E%E6%8E%A5%E9%9B%86%E7%BE%A4"><span class="toc-number">1.0.21.</span> <span class="toc-text">21. java使用jedis连接集群</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2021/03/21/%E9%9D%A2%E8%AF%95-%E5%B9%B6%E5%8F%91%E3%80%81%E5%A4%9A%E7%BA%BF%E7%A8%8B/" title="面试题-并发编程"><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/BEF238F4E59CF4D91A694FE9C5DBC030.JPG" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="面试题-并发编程"/></a><div class="content"><a class="title" href="/2021/03/21/%E9%9D%A2%E8%AF%95-%E5%B9%B6%E5%8F%91%E3%80%81%E5%A4%9A%E7%BA%BF%E7%A8%8B/" title="面试题-并发编程">面试题-并发编程</a><time datetime="2021-03-20T16:00:00.000Z" title="发表于 2021-03-21 00:00:00">2021-03-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/03/20/%E9%9D%A2%E8%AF%95-%E9%9B%86%E5%90%88/" title="面试题-集合框架"><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/BEF238F4E59CF4D91A694FE9C5DBC030.JPG" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="面试题-集合框架"/></a><div class="content"><a class="title" href="/2021/03/20/%E9%9D%A2%E8%AF%95-%E9%9B%86%E5%90%88/" title="面试题-集合框架">面试题-集合框架</a><time datetime="2021-03-19T16:00:00.000Z" title="发表于 2021-03-20 00:00:00">2021-03-20</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/03/20/Java-%E6%BA%90%E7%A0%81-JDK8-HashMap/" title="JDK8 HashMap源码"><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/BEF238F4E59CF4D91A694FE9C5DBC030.JPG" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JDK8 HashMap源码"/></a><div class="content"><a class="title" href="/2021/03/20/Java-%E6%BA%90%E7%A0%81-JDK8-HashMap/" title="JDK8 HashMap源码">JDK8 HashMap源码</a><time datetime="2021-03-19T16:00:00.000Z" title="发表于 2021-03-20 00:00:00">2021-03-20</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/03/13/The%20Road%20To%20Bald%20Man!/" title="The Road To Bald Man!"><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/BEF238F4E59CF4D91A694FE9C5DBC030.JPG" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="The Road To Bald Man!"/></a><div class="content"><a class="title" href="/2021/03/13/The%20Road%20To%20Bald%20Man!/" title="The Road To Bald Man!">The Road To Bald Man!</a><time datetime="2021-03-12T16:00:00.000Z" title="发表于 2021-03-13 00:00:00">2021-03-13</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2020/07/21/%E6%A1%86%E6%9E%B6-Maven-%E9%85%8D%E7%BD%AE%E6%A0%87%E7%AD%BE%E8%AF%A6%E8%A7%A3/" title="Maven配置标签详解"><img src="https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/BEF238F4E59CF4D91A694FE9C5DBC030.JPG" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Maven配置标签详解"/></a><div class="content"><a class="title" href="/2020/07/21/%E6%A1%86%E6%9E%B6-Maven-%E9%85%8D%E7%BD%AE%E6%A0%87%E7%AD%BE%E8%AF%A6%E8%A7%A3/" title="Maven配置标签详解">Maven配置标签详解</a><time datetime="2020-07-20T16:00:00.000Z" title="发表于 2020-07-21 00:00:00">2020-07-21</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('https://fangchenyong.oss-cn-hangzhou.aliyuncs.com/img/20190723151525.png')"><div id="footer-wrap"><div class="copyright">&copy;2019 - 2021 By 方陈勇</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">人生没有退路！</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><div class="js-pjax"></div><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-nest.min.js"></script></div></body></html>